package com.ling.service;

import com.ling.bean.Subscribe;
import com.ling.bean.SubscribeExample;
import com.ling.dao.SubscribeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubscribeService {
    private final SubscribeMapper subscribeMapper;

    @Autowired
    public SubscribeService(SubscribeMapper subscribeMapper) {
        this.subscribeMapper = subscribeMapper;
    }

    //保存订阅信息
    public void saveSubscribe(Subscribe subscribe) {
        subscribeMapper.insertSelective(subscribe);
    }

    //判断是否已经订阅
    public boolean existRecord(String userId) {
        SubscribeExample subscribeExample = new SubscribeExample();
        subscribeExample.createCriteria().andUseridEqualTo(userId);
        return subscribeMapper.countByExample(subscribeExample) > 0;
    }

    //获取指定week的邮件发送列表
    public List<Subscribe> getUserEmailList(int week) {
        return subscribeMapper.getUserEmailList(week);
    }

}
